package com.qihoo.finance.fake.module.threadpool.facade;


import com.qihoo.finance.fake.module.threadpool.entity.ThreadPoolInfoEntity;
import com.qihoo.finance.fake.module.threadpool.service.ThreadService;
import com.qihoo.finance.msf.api.domain.Response;
import com.qihoo.finance.msf.api.threadpool.domain.ThreadPoolInfoDomain;
import com.qihoo.finance.msf.api.threadpool.facade.ThreadPoolFacade;
import com.qihoo.finance.msf.core.utils.BeanUtils2;
import com.qihoo.finance.msf.core.utils.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by Huang on 2016/8/17.
 */
@Service("threadPoolFacadeImpl")
public class ThreadPoolFacadeImpl implements ThreadPoolFacade {
    private static final Logger logger = LogManager.getLogger(ThreadPoolFacadeImpl.class);

    @Resource
    private ThreadService threadService;

    @Override
    public Response<List<ThreadPoolInfoDomain>> queryThreadPoolInfoList(String module) {
        if (StringUtils.isBlank(module)){
            logger.warn("module is empty. module={}", module);
            return new Response().fail();
        }
        try {
            List<ThreadPoolInfoEntity> threadPoolInfoList = threadService.getThreadPoolInfoList(module);
            List<ThreadPoolInfoDomain> threadPoolInfoDomainList = BeanUtils2.copyBeanList(ThreadPoolInfoDomain.class, threadPoolInfoList);
            return new Response().success(threadPoolInfoDomainList);
        }catch(Exception e){
            logger.error("getThreadPoolInfoList error. module={}", module, e);
            return new Response().fail();
        }
    }
}
